package com.woniuxy.yygh.hsop.controller.api;

import com.woniuxy.yygh.common.result.Result;
import com.woniuxy.yygh.hsop.service.DepartmentService;
import com.woniuxy.yygh.hsop.service.HospitalService;
import com.woniuxy.yygh.hsop.service.HospitalSetService;
import com.woniuxy.yygh.hsop.service.ScheduleService;
import com.woniuxy.yygh.model.hosp.Hospital;
import com.woniuxy.yygh.model.hosp.Schedule;
import com.woniuxy.yygh.vo.hosp.DepartmentVo;
import com.woniuxy.yygh.vo.hosp.HospitalQueryVo;
import com.woniuxy.yygh.vo.hosp.ScheduleOrderVo;
import com.woniuxy.yygh.vo.order.SignInfoVo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <P> @Author: ideaAdmin
 * <P> TODO: Class
 * <P> TODO: 前台用户调用的hospController
 * <P> Date: 2022/3/3:12:12
 * <P> Description:
 */

@RestController
@RequestMapping("/api/hosp/hospital")
public class HospApiController {

    //直接调用医院接口
    @Autowired
    private HospitalService hospitalService;

    //科室接口
    @Autowired
    private DepartmentService departmentService;

    //排版信息接口
    @Autowired
    private ScheduleService scheduleService;

    //直接调用医院设置接口
    @Autowired
    private HospitalSetService hospitalSetService;

    /**
     * TODO:查询医院列表 并且分页
     * 实体可以根据省 市 区 和医院名字来查询
     **/
    @ApiOperation(value = "查询医院的列表功能")
    @GetMapping("/findHospList/{page}/{limit}")
    public Result findHospList(@PathVariable Integer page,
                               @PathVariable Integer limit,
                               HospitalQueryVo hospitalQueryVo) {
        Page<Hospital> hospitals = hospitalService.selectHospPage(page, limit, hospitalQueryVo);
        return Result.ok(hospitals);
    }


    /**
     * TODO:根据医院名称做模糊查询
     **/
    @ApiOperation(value = "根据医院名称做模糊查询")
    @GetMapping("/findByHosName/{hosname}")
    public Result findByHosName(@PathVariable String hosname) {
        List<Hospital> hospitals = hospitalService.findByHosName(hosname);
        return Result.ok(hospitals);
    }

    /**
     * TODO:根据医院编号 查询所有的科室列表信息
     **/
    @ApiOperation(value = "根据医院编号 查询所有的科室列表")
    @GetMapping("/department/{hoscode}")
    public Result index(@PathVariable String hoscode) {
        List<DepartmentVo> deptTree = departmentService.findDeptTree(hoscode);
        return Result.ok(deptTree);
    }

    /**
     * TODO:根据医院编号 获取医院预约挂号详情
     **/
    @ApiOperation(value = "根据医院编号 获取医院预约挂号详情 和医院的信息")
    @GetMapping("findHospDetail/{hoscode}")
    public Result item(@PathVariable String hoscode) {
        Map<String, Object> map = hospitalService.item(hoscode);
        return Result.ok(map);
    }

    /**
     * TODO:根据医院编号和科室编号 获取可预约的排班数据
     **/
    @ApiOperation(value = "获取可预约排班数据")
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result getBookingSchedule(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Integer page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Integer limit,
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depcode) {
        return Result.ok(scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode));
    }

    /**
     * TODO:根据医院编号 科室编号 排版日期 获取排班数据
     **/
    @ApiOperation(value = "获取排班数据")
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result findScheduleList(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depcode,
            @ApiParam(name = "workDate", value = "排班日期", required = true)
            @PathVariable String workDate) {

        return Result.ok(scheduleService.getDetailSchedule(hoscode, depcode, workDate));
    }


    /**
     * TODO:获取排班id 获得排班的数据
     **/
    @GetMapping("/getSchedule/{scheduleId}")
    public Result getSchedule(@PathVariable String scheduleId) {
        Schedule schedule = scheduleService.getScheduleById(scheduleId);
        return Result.ok(schedule);
    }

    /**
     * TODO:根据排班id获取预约下单数据
     **/
    @ApiOperation(value = "根据排班id获取预约下单数据")
    @GetMapping("/inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(
            @ApiParam(name = "scheduleId", value = "排班id", required = true)
            @PathVariable("scheduleId") String scheduleId) {

        return scheduleService.getScheduleOrderVo(scheduleId);
    }

    /**
     * TODO:根据医院编号获取医院签名信息
     **/
    @ApiOperation(value = "根据医院编号获取医院签名信息")
    @GetMapping("/inner/getSignInfoVo/{hoscode}")
    public SignInfoVo getSignInfoVo(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable("hoscode") String hoscode) {
        return hospitalSetService.getSignInfoVo(hoscode);
    }

}
